home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / ip / dialupip / dialupip2.0 / src / fixmake.c next >
Encoding:
C/C++ Source or Header  |  1991-01-11  |  3.2 KB  |  131 lines

  1. /*
  2. **  For systems whose make doesn't handle "include filename" syntax, this
  3. **  program reads in "Makefile" and creates "makefile".
  4. **
  5. **  Usage:
  6. **    fixmake [-i <filename>] [-o <filename>]
  7. **        -i <filename>    Set input filename, default is "Makefile"
  8. **        -o <filename>    Set output filename, default is "makefile"
  9. **
  10. **  Copyright (c) 1991 Bolt Beranek and Newman, Inc.
  11. **  All rights reserved.
  12. **
  13. **  Redistribution and use in source and binary forms are permitted
  14. **  provided that: (1) source distributions retain this entire copyright
  15. **  notice and comment, and (2) distributions including binaries display
  16. **  the following acknowledgement:  ``This product includes software
  17. **  developed by Bolt Beranek and Newman, Inc. and CREN/CSNET'' in the
  18. **  documentation or other materials provided with the distribution and in
  19. **  all advertising materials mentioning features or use of this software.
  20. **  Neither the name of Bolt Beranek and Newman nor CREN/CSNET may be used
  21. **  to endorse or promote products derived from this software without
  22. **  specific prior written permission.
  23. **
  24. **  THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  25. **  WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  26. **  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  27. */
  28. #include <stdio.h>
  29.  
  30. #define SUCCESS        0
  31. #define FAILURE        1
  32.  
  33. static char    *progname;
  34. extern char    *optarg;
  35. extern int    optind;
  36.  
  37.  
  38.  
  39. static int
  40. process_file(in_name, outfile)
  41.     char    *in_name;
  42.     FILE    *outfile;
  43. {
  44.     char    buff[BUFSIZ];
  45.     FILE    *F;
  46.     char    name[BUFSIZ];
  47.  
  48.     /* Open the input file */
  49.     if ((F = fopen(in_name, "r")) == NULL) {
  50.     perror(in_name);
  51.     fprintf(stderr, "Can't open for reading.\n");
  52.     return FAILURE;
  53.     }
  54.  
  55.     /* While input lines exist, read them */
  56.     while (fgets(buff, sizeof buff, F)) {
  57.     /* Is this an 'include' line? */
  58.     if (sscanf(buff, "include%*[ \t]%[^ \t\n]", name) == 1) {
  59.         /* Process the file and try to fix include the file */
  60.         if (process_file(name, outfile) == FAILURE)
  61.         return FAILURE;
  62.         continue;
  63.     }
  64.     /* Otherwise just copy to the output */
  65.     fprintf(outfile, buff);
  66.     }
  67.  
  68.     /* Close the input file and return success */
  69.     (void)fclose(F);
  70.     return SUCCESS;
  71. }
  72.  
  73.  
  74. static void
  75. usage()
  76. {
  77.     fprintf(stderr, "%s [-i inputfile] [-o outputfile]\n", progname);
  78.     exit(1);
  79. }
  80.  
  81.  
  82. main(argc, argv)
  83.     int        argc;
  84.     char    *argv[];
  85. {
  86.     FILE    *F;
  87.     char    *in_name;
  88.     char    *out_name;
  89.     int        i;
  90.  
  91.     /* Set defaults. */
  92.     progname = argv[0];
  93.     in_name = "Makefile";
  94.     out_name = "makefile";
  95.  
  96.     /* Parse flags. */
  97.     while ((i = getopt(argc, argv, "i:o:")) != EOF)
  98.     switch (i) {
  99.     default:        /* Error in command arguments     */
  100.         usage();
  101.         /* NOTREACHED */
  102.     case 'i':        /* Set input filename         */
  103.         in_name = optarg;
  104.         break;
  105.     case 'o':        /* Set output filename         */
  106.         out_name = optarg;
  107.         break;
  108.     }
  109.  
  110.     /* Parse the parameters. */
  111.     argc -= optind;
  112.     argv += optind;
  113.     if (*argv)
  114.     usage();
  115.  
  116.     /* Open the output filename */
  117.     if ((F = fopen(out_name, "w")) == NULL) {
  118.     perror(out_name);
  119.     fprintf(stderr, "Can't open for writing.\n");
  120.     exit(1);
  121.     }
  122.  
  123.     /* Run. */
  124.     i = process_file(in_name, F);
  125.  
  126.     /* Close the output file */
  127.     (void)fclose(F);
  128.     exit(i);
  129.     /* NOTREACHED */
  130. }
  131.